import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'app/routes/app_pages.dart';

/// 主类
class MyApp extends StatelessWidget with WidgetsBindingObserver {
  const MyApp({super.key});

  /// APP生命周期回调
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        print('应用程序可见并响应用户输入。');
        break;
      case AppLifecycleState.inactive:
        print('应用程序处于非活动状态，并且未接收用户输入');
        break;
      case AppLifecycleState.paused:
        print('用户当前看不到应用程序，没有响应');
        break;
      case AppLifecycleState.detached:
        print('应用程序将暂停。');
        break;
      default:
    }
  }

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: "WebFlutterApp",
      initialRoute: AppPages.INITIAL,
      getPages: AppPages.routes,
      // 主题颜色跟随系统改变而改变
      themeMode: ThemeMode.system,
      // GetXApplication 初始化
      onInit: () {
        WidgetsBinding.instance.addObserver(this);
      },
      // 未知路由
      onUnknownRoute: (settings) {
        Get.toNamed(Routes.NOT_FOUND);
        return;
      },
      // GetXApplication 准备完毕
      onReady: () {},
      // GetXApplication 销毁完毕
      onDispose: () {
        WidgetsBinding.instance.removeObserver(this);
      },
      // 不显示DEBUG
      debugShowCheckedModeBanner: false,
      // 主题
      theme: ThemeData(
          // 状态栏颜色设置为透明
          appBarTheme: const AppBarTheme(
              systemOverlayStyle:
                  SystemUiOverlayStyle(statusBarColor: Colors.transparent))),
    );
  }
}

/// 程序入口
void main() {
  // 初始化
  WidgetsFlutterBinding.ensureInitialized();
  // 运行程序
  runApp(const MyApp());
}
